package com.yanqu.road.dao.impl.activity.guguoxunbao;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.guguoxunbao.GuGuoXunBaoClueComment;
import com.yanqu.road.entity.activity.guguoxunbao.GuGuoXunBaoPlace;
import com.yanqu.road.entity.activity.guguoxunbao.GuGuoXunBaoTreasure;
import com.yanqu.road.utils.string.StringUtils;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class GuGuoXunBaoConfigDaoImpl extends TempDao {

    public static String getGuGuoXunBaoClueCommentSql = "select * from t_s_activity_xunbao_clue where activityId= ?";
    public Map<Integer, GuGuoXunBaoClueComment> getGuGuoXunBaoClueComment(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, GuGuoXunBaoClueComment> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getGuGuoXunBaoClueCommentSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                GuGuoXunBaoClueComment data = new GuGuoXunBaoClueComment();
                data.setId(rs.getInt("id"));
                data.setNum(StringUtils.stringToIntegerList(rs.getString("num"), ","));
                data.setDesc(rs.getString("desc"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }


    public static String getGuGuoXunBaoPlaceSql = "select * from t_s_activity_xunbao_place where activityId= ?";
    public Map<Integer, GuGuoXunBaoPlace> getGuGuoXunBaoPlace(int activityId){
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, GuGuoXunBaoPlace> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getGuGuoXunBaoPlaceSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                GuGuoXunBaoPlace data = new GuGuoXunBaoPlace();
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setClueNum(rs.getInt("clueNum"));
                data.setTreasureId(rs.getInt("treasureId"));
                data.setRewards(rs.getString("rewards"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }


    public static String getGuGuoXunBaoTreasureSql = "select * from t_s_activity_xunbao_treasure where activityId= ?";
    public Map<Integer, GuGuoXunBaoTreasure> getGuGuoXunBaoTreasure(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, GuGuoXunBaoTreasure> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(getGuGuoXunBaoTreasureSql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                GuGuoXunBaoTreasure data = new GuGuoXunBaoTreasure();
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setValue(rs.getInt("value"));
                data.setRewards(rs.getString("rewards"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
